package servlet;

import java.io.IOException;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.BookService;
import service.BorrowService;
import service.ReaderSerivice;
import vo.BookBean;

public class BookReturn extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
String rid= req.getParameter("rid");
String bid= req.getParameter("bid");
String oid= req.getParameter("oid");
Double rmoney= Double.parseDouble(req.getParameter("rmoney"));
Date time=new Date();
String rtime=DateFormat.getDateInstance().format(time);
BorrowService bws=new BorrowService();
bws.returnBook(oid, rtime);
BookService bs=new BookService();
bs.update(bid);
 List<Object> list = bs.get(Integer.parseInt(bid));
 BookBean bb=(BookBean) list.get(0);
 Double mn=bb.getB_price()-rmoney;
 ReaderSerivice rs=new ReaderSerivice();
 rs.update(rid, mn);
 req.getRequestDispatcher("/jsp/book/bookreturn_list").forward(req, resp);
 
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	doGet(req, resp);
	}
}
